package com.lmm.lcuser.lc_user.pages;

import com.baidu.mapapi.model.LatLng;
import com.lmm.dresswisdom.lmmframe.retrofit.AppCallBack;
import com.lmm.dresswisdom.lmmframe.retrofit.AppClient;
import com.lmm.dresswisdom.lmmframe.util.LogUtils;
import com.lmm.lcuser.lc_user.BaseReturnInfo;
import com.lmm.lcuser.lc_user.commonbean.ShopBean;
import com.lmm.lcuser.lc_user.config.AppInfoAction;
import com.lmm.lcuser.lc_user.config.ConfigValue;
import com.lmm.lcuser.lc_user.config.DataSafeUtil;

import org.json.JSONObject;

import java.util.List;
import java.util.Map;

public class ShopMapPresent implements ShopMapContract.IPresent {

    ShopMapContract.IView mView;
    ShopMapAction mAction;

    public ShopMapPresent(ShopMapContract.IView mView) {
        this.mView = mView;
        mAction = AppClient.getRetrofit(ConfigValue.apiUrl).create(ShopMapAction.class);
    }

    @Override
    public void getShopLst(LatLng point) {
        Map<String, String> params = AppInfoAction.getParams();
        params.put("lat", String.valueOf(point.latitude));
        params.put("lon", String.valueOf(point.longitude));
        params.put("precision", String.valueOf(2));

        AppClient.request(mAction.getNearShop(DataSafeUtil.EncodeMAP(params)), new AppCallBack<BaseReturnInfo<List<ShopBean>>>() {
            @Override
            public void onSuccess(BaseReturnInfo<List<ShopBean>> res) {
                if (res.isSuccess()) {
                    mView.setNearShop(res.getData());
                }
            }

            @Override
            public void onFailure(String s) {
                LogUtils.write(s);
            }

            @Override
            public void onFinish() {

            }
        });
    }
}